<%--                                                                       --%>
<%-- Copyright (c) 2005 BroadVision, Inc.  All rights reserved.            --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<%
  String ctxPath = request.getContextPath();
%>

<script language="JavaScript">

function doPageTypeSelect(form) {
  var selectedIds = "";
  selectedIds += "<c:forEach var="page" items="${epUserTemplatePagesView.map.pages}"><c:out value="${page.map.id}"/>;</c:forEach>";
  doPickerPopupAction('<c:url value="/mt/pickerPopupSearchMultiSelect.do"/>', 'setPageTypes',
    307, null, selectedIds, null, false, true, false, null, null, null, null, null, null, false, true);
}

function setPageTypes(ids, names) {
  document.epUserTemplatePagesForm.pageTypeIds.length = 0;
  for (var index = 0; index < ids.length; index++) {
    var option = new Option(names[index], ids[index], true, true);
    document.epUserTemplatePagesForm.pageTypeIds.options[index] = option;
  }
  document.epUserTemplatePagesForm.submit();
}

function doPageTypesRemove(form) {
  form.action = "<c:url value="/ep/userTemplatePagesRemove.do"/>";
  form.submit();
}

function doEditAction(form) {
  form.action = "<c:url value="/ep/userTemplatePagesEdit.do"/>";
  form.actionEdit.value = 'true';
  form.submit();
}

<%@ include file="/mc/common/jsutils.jsp" %>

</script>

<%@include file="/mt/common/pickerPopupHelper.jsp" %>

<c:set var="removeImg">
<img src="<%= ctxPath %>/ep/images/action/icon_remove.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.remove" bundle="ep.messages"/>" title="<bean-el:message key="image.alt.remove" bundle="ep.messages"/>">
</c:set>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle">
        <bean-el:message key="ep.user.template.view.page.title" bundle="ep.messages" arg0="${epUserTemplatePagesView.map.name}"/>
      </div>
      <div class="errorMessage"><html-el:errors/></div>
      <%@ include file="/mc/common/pagetab.jsp" %>

      <html-el:form action="/ep/userTemplatePagesSave.do">
        <input type="hidden" name="userTemplateId" value="<c:out value="${epUserTemplatePagesView.map.id}"/>"/>
        <input type="hidden" name="actionEdit" value="false"/>
        <div class="pageSubtitle">
          <span class="left"><bean-el:message key="ep.user.template.page.types.selected" bundle="ep.messages"/></span>
          <span class="right">
            <input type="button" class="inputButton" value='<bean-el:message key="button.page.types.select" bundle="ep.messages"/>'
              onclick="doPageTypeSelect(this.form);">
<c:if test="${not empty epUserTemplatePagesView.map.pages}">
            <input type="button" class="inputButton" value='<bean-el:message key="button.edit" bundle="ep.messages"/>'
              onclick="doEditAction(this.form);">
</c:if>
          </span>
        </div>
        <select name="pageTypeIds" multiple="multiple" size="0" style="visibility: hidden; display: none;"></select>
      </html-el:form>

      <html-el:form action="/ep/userTemplatePagesOrderSave.do">
        <input type="hidden" name="userTemplateId" value="<c:out value="${epUserTemplatePagesView.map.id}"/>"/>
<c:if test="${not empty epUserTemplatePagesView.map.pages}">
        <div class="globalButtonWrap">
          <input type="button" class="globalButton" name="selectAll" value="<bean-el:message key="button.selectAll" bundle="ep.messages"/>"
            onclick="check(this.form.pageTypeIds, this);">
          <input type="button" class="globalButton" value="<bean-el:message key="button.remove" bundle="ep.messages"/>"
            onclick="if (isAnyChecked(this.form.pageTypeIds, '<bean-el:message key="ep.page.types.atLeastOne" bundle="ep.messages"/>', '')) doPageTypesRemove(this.form);">
        </div>
</c:if>
        <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Search result table" width="100%">
          <tr class="listHeader">
            <th id="Checkboxes" align="center" width="1%">&nbsp;</th>
            <th id="Name" align="left" width="40%"><bean-el:message key="ep.header.name" bundle="ep.messages"/></th>
            <th id="Description" align="left" width="40%"><bean-el:message key="ep.header.description" bundle="ep.messages"/></th>
            <th id="Order" align="right" width="5%"><bean-el:message key="ep.header.order" bundle="ep.messages"/></th>
            <th id="Type" align="left" width="7%"><bean-el:message key="ep.header.name.type" bundle="ep.messages"/></th>
            <th id="Actions" align="left" width="7%"><bean-el:message key="ep.header.actions" bundle="ep.messages"/></th>
          </tr>
<c:choose>
  <c:when test="${empty epUserTemplatePagesView.map.pages}">
          <tr class="listOdd">
            <td align="center" colspan="6">
              <bean-el:message key="ep.user.template.page.types.noFound" bundle="ep.messages"/>
            </td>
          </tr>
  </c:when>
  <c:otherwise>
    <c:forEach var="page" items="${epUserTemplatePagesView.map.pages}" varStatus="index">
      <c:url var="removeUrl" value="/ep/userTemplatePagesRemove.do">
        <c:param name="userTemplateId" value="${epUserTemplatePagesView.map.id}"/>
        <c:param name="pageTypeId" value="${page.map.id}"/>
      </c:url>
      <c:choose>
        <c:when test="${(index.count + 1) % 2 == 0}">
          <tr class="listEven">
        </c:when>
        <c:otherwise>
          <tr class="listOdd">
        </c:otherwise>
      </c:choose>
            <td headers="Checkboxes" align="center">
              <input type="checkbox" name="pageTypeIds" onclick="update(this.form.pageTypeIds, this.form.selectAll);"
                value="<c:out value="${page.map.id}"/>">
              <input type="hidden" name="pageIds" value="<c:out value="${page.map.id}"/>"/>
            </td>
            <td headers="Name"><c:out value="${page.map.name}"/></td>
            <td headers="Description"><c:out value="${page.map.description}"/></td>
            <td headers="Order" align="right">
              <c:if test="${page.map.order > 0}"><c:out value="${page.map.order}"/></c:if>
            </td>
            <td headers="Type" align="left">
              <c:if test="${page.map.type == 2}"><bean-el:message key="ep.user.template.page.types.type.required" bundle="ep.messages"/></c:if>
              <c:if test="${page.map.type == 1}"><bean-el:message key="ep.user.template.page.types.type.default" bundle="ep.messages"/></c:if>
              <c:if test="${page.map.type == 0}"><bean-el:message key="ep.user.template.page.types.type.optional" bundle="ep.messages"/></c:if>
            </td>
            <td headers="Actions"><a href="<c:out value="${removeUrl}"/>"><c:out value='${removeImg}' escapeXml="false"/></a></td>
          </tr>
    </c:forEach>
  </c:otherwise>
</c:choose>
        </table>
      </html-el:form>
    </td>
  </tr>
</table>
